﻿#if defined(_WIN32)
#include <conio.h>
#elif defined(linux) || defined(__linux) || defined(__linux__)
#include "conio.h"
#endif

#include <stdio.h>
#include <string.h>

const char * const PASSWORD = "universe";

int main()
{
	char password[BUFSIZ];
	size_t length = strlen(PASSWORD);
	size_t counter = 0;

	int key;
	printf("输入密码：");
	while (key = getch())
	{
		password[counter] = key;
		if (key == '\b' || key == 127)
		{
			if (counter > 0)
			{
				printf("\b \b");
				--counter;
			}
		}
		else
		{
			if (key == '\r' || key == '\n')
				break;
			putchar('*');
			++counter;
			if (counter >= length)
				break;
		}
	}
	password[counter] = '\0';

	if (strcmp(password, PASSWORD) == 0)
		puts("\n验证通过！");
	else
		puts("\n密码错误！");
	return 0;
}
